package ServiceLayer;

import java.util.Collection;

import DAL.Pipeline;
import DALFacades.IFacade;

import DomainLayer.Common.*;
import DomainLayer.FeedBackEntity;
import DomainLayer.UserEntity;

import Helpers.ApplicationLogger;

public class ServiceFacade {

	private IFacade currentFacade;


    private static final class Nested {

        static final ServiceFacade _instance = new ServiceFacade();
    }
	public static ServiceFacade getInstance() {
		return Nested._instance;
	}

	public ServiceFacade() {
		currentFacade = Pipeline.getInstance().getFacade();
	}

	public UserEntity AuthentificationByLoginAndPassword(String login,
			String password) throws Throwable {
		ApplicationLogger.getInstance().LOG
				.info("Call method AuthentificationByLoginAndPassword");

		UserEntity user = null;

		user = currentFacade
				.AuthentificationByLoginAndPassword(login, password);
		ApplicationLogger.getInstance().LOG.info("Result is " + user);
		return user;
	}

	public Boolean UpdateUser(UserEntity user) throws Throwable {
		Boolean result = false;
		result = currentFacade.UpdateUser(user);
		return result;
	}

	public UserEntity GetUserById(int id) {
		ApplicationLogger.getInstance().LOG.info("Call method GetUserById");

		UserEntity user = null;
		user = currentFacade.GetUserById(id);
		ApplicationLogger.getInstance().LOG.info("Result is " + user);
		return user;
	}

	public Boolean AddFeedBack(String page, String from, String message)
			throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method AddFeedBack");
		Boolean result = false; 
		result = currentFacade.SetFeedBackEntity(message, from, page);
		ApplicationLogger.getInstance().LOG.info("Status of AddFeedBack is "
				+ result);
		return result;
	}

	public Collection<FeedBackEntity> GetFeedBack() throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method GetFeedBack");
		Collection<FeedBackEntity> feedbacklist = null;
		feedbacklist = currentFacade.GetFeedBackEntity();
		ApplicationLogger.getInstance().LOG.info("Result is" + feedbacklist);
		return feedbacklist;
	}

	public Boolean RegistrationUser(String firstName, String secondName,
			String middleName, String login, String password, String gender,
			Integer age, String sessionId, String lastIP) throws Throwable {
		ApplicationLogger.getInstance().LOG
				.info("Call method RegistrationUser");
		Boolean result = false;
		result = currentFacade.AddUser(firstName, secondName, middleName,
				login, password, gender, age, sessionId, lastIP);
		ApplicationLogger.getInstance().LOG.info("Registration is resolved: "
				+ result);
		return result;
	}

	public Boolean ChangeUser(String login, String password, String firstName,
			String secondName, String middleName, String gender, Integer age)
			throws Throwable {
		ApplicationLogger.getInstance().LOG.info("Call method ChangeUser");
		Boolean result = false;
		result = currentFacade.ChangeUser(login, password, firstName,
				secondName, middleName, gender, age);
		ApplicationLogger.getInstance().LOG.info("Change is resolved: "
				+ result);
		return result;
	}
}
